package at.ac.tuwien.infosys.aic11.services;


import javax.ws.rs.PathParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;

import at.ac.tuwien.infosys.aic11.dto.InternalCustomer;
import at.ac.tuwien.infosys.aic11.dto.Rating;
import at.ac.tuwien.infosys.aic11.dto.Warrantor;
import at.ac.tuwien.infosys.aic11.fault.UnknownCustomerFault;
import at.ac.tuwien.infosys.aic11.fault.UnknownRequestFault;
import at.ac.tuwien.infosys.aic11.legacy.RatingMock;
import at.ac.tuwien.infosys.aic11.server.DataBase;
import at.ac.tuwien.infosys.aic11.services.RatingService;


import java.util.List;
import java.util.logging.Logger;


public class RatingServiceImpl implements RatingService{

	private static Logger log = Logger.getLogger("at.ac.tuwien.infosys.aic11.services.RatingServiceImpl");
	static {
		log.setParent(Logger.getLogger("at.ac.tuwien.infosys.aic11.services"));
	}

	@Override
	public Rating getRating(@PathParam("customername") String customerName) {
		log.info("Call to getRating() for Customer " + customerName);

		if(customerName==null || customerName.length()<=0){
			log.severe("getRating(): customerName may not be null");
			throw new WebApplicationException(Response.Status.BAD_REQUEST);
		}		
		
		Rating r = RatingMock.getCustomerRating(customerName);
		
		log.info("getRating() returns rating: " + r.getRating() + " for Customer " + customerName);

		return r;


	}

	@Override
	public List<InternalCustomer> getCustomers() {
		log.info("Call to getCustomers()");
		List<InternalCustomer> lst = DataBase.getInternalCustomers();
		log.info("Returning list with " + lst.size() + " customers");
		return lst;
	}

	@Override
	public List<Warrantor> getWarrantors() {
		log.info("Call to getWarrantors()");
		List<Warrantor> lst = DataBase.getWarrantors();
		log.info("Returning list with " + lst.size() + " warrantors");
		return lst;
	}
}
